package testOne2Ten;

import java.awt.image.RGBImageFilter;

/**
 * 求旋转数组的最小数字{1,2,3,4,5} -> {3,4,5,1,2}
 * Created by Wongy on 2018/3/13.
 */
public class test8 {
    private static int getMinNumInArray(int[] array) {
        if (array == null || array.length == 0) {
            return 0;
        }
        int left = 0;
        int right = array.length - 1;
        int mid = 0;
        while (array[left] > array[right]) {
            if (right - left <= 1) {
                mid = right;
                break;
            }
            mid = (left + right) / 2;
            if (array[left] == array[mid] && array[right] == array[mid]) {
                if (array[left + 1] != array[right - 1]) {
                    mid = array[left + 1] < array[right - 1] ? left + 1 : right - 1;
                } else {
                    left++;
                    right--;
                }
            } else {
                if (array[left] <= array[mid]) {
                    left = mid;
                } else {
                    right = mid;
                }
            }
        }

        return 0;
    }
}
